cmake_minimum_required(VERSION 3.12)
project(matplotlibcpp VERSION 1.2)
set(CMAKE_BUILD_TYPE release)
add_library(${PROJECT_NAME} INTERFACE)
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
find_package(Python3 COMPONENTS NumPy REQUIRED)
target_link_libraries(${PROJECT_NAME} INTERFACE Python3::Python Python3::NumPy)
target_include_directories(${PROJECT_NAME} INTERFACE ${Python3_INCLUDE_DIRS} ${Python3_NumPy_INCLUDE_DIRS})

if (WIN32)
    add_definitions(-DSYS_WINDOWS)
    set(CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib)
    set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/include)
    set(PYTHON_HOME ${Python3_INCLUDE_DIRS}/..)
    configure_file(${PROJECT_SOURCE_DIR}/cmake/pythonhome.h.in pythonhome.h)
elseif (UNIX)
    include(GNUInstallDirs)
endif ()

set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "INSTALL_CONFIGDIR: ${INSTALL_CONFIGDIR}")
message(STATUS "CMAKE_INSTALL_INCLUDEDIR: ${CMAKE_INSTALL_INCLUDEDIR}")
message(STATUS "Python3_LIBRARIES: ${Python3_LIBRARIES}")
message(STATUS "Python3_INCLUDE_DIRS: ${Python3_INCLUDE_DIRS}")
message(STATUS "Python3_NumPy_INCLUDE_DIRS: ${Python3_NumPy_INCLUDE_DIRS}")

include(CMakePackageConfigHelpers)
configure_package_config_file(
    ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
    ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
    INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
install(TARGETS ${PROJECT_NAME}
    EXPORT install_targets
    INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(EXPORT install_targets
    FILE ${PROJECT_NAME}Targets.cmake
    NAMESPACE ${PROJECT_NAME}::
    DESTINATION ${INSTALL_CONFIGDIR}
)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/matplotlibcpp.h
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
    DESTINATION ${INSTALL_CONFIGDIR}
)
if (WIN32)
    install(FILES ${PROJECT_BINARY_DIR}/pythonhome.h
        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
    )
endif ()
